#ifndef HMC5883_H
#define HMC5883_H

#include "stm32f1xx_hal.h"
#include "i2c.h"
#include "math.h"
#include "usart.h"

/*地址定义*/
#define HMC5883_ADDRESS 0x1E // HMC5883 I2C address
#define HMC58883_CONFIGA 0x00 // Configuration register A
#define HMC5883_CONFIGB 0x01 // Configuration register B
#define HMC5883_MODE 0x02 // Mode register
#define HMC5883_DATA_X_MSB 0x03 // X-axis MSB data register 
#define HMC5883_DATA_X_LSB 0x04 // X-axis LSB data register
#define HMC5883_DATA_Z_MSB 0x05 // Z-axis MSB data register
#define HMC5883_DATA_Z_LSB 0x06 // Z-axis LSB data register
#define HMC5883_DATA_Y_MSB 0x07 // Y-axis MSB data register
#define HMC5883_DATA_Y_LSB 0x08 // Y-axis LSB data register
#define HMC5883_STATUS 0x09 // Status register
#define HMC5883_ID_A 0x0A // ID register A
#define HMC5883_ID_B 0x0B // ID register B
#define HMC5883_ID_C 0x0C // ID register C

/*寄存器定义*/
#define HMC5883_MODE_CONTINUOUS 0x00 // Continuous mode
#define HMC5883_ID_A_VALUE 0x48 // ID A value
#define HMC5883_ID_VALUE 0x00483433 // ID value (A, B, C concatenated)


/*函数定义*/
void HMC5883_Init(I2C_HandleTypeDef *hi2c); // 初始化HMC5883
void HMC5883_ReadData(I2C_HandleTypeDef *hi2c, int *data); // 读取HMC5883数据

#endif
